home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000131_icon-group-sender _Mon Jun 10 17:45:25 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 11 Jun 1996 07:45:48 MST
  2. To: icon-group@cs.arizona.edu
  3. Date: Mon, 10 Jun 1996 17:45:25 GMT
  4. From: pardoej@lonnds.ml.com (Julian Pardoe LADS LDN X1428)
  5. Message-Id: <DsspBq.M1s@tigadmin.ml.com>
  6. Organization: Merrill Lynch Europe
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <Dsqq4z.AsA@eskimo.com>
  9. Reply-To: pardoej@lonnds.ml.com
  10. Subject: Re: m3 should have SWAP(a,b)
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: O
  13.  
  14. In article <Dsqq4z.AsA@eskimo.com>, leeo@eskimo.com (Lee Odegard) writes:
  15. -->dave@CS.Arizona.EDU (Dave Schaumann) writes:
  16. -->
  17. -->>As you say.  For my part, the only time I've found 'swap' to be a useful
  18. -->>operation is when I am writing sort algorithm (or sort-related algorithms,
  19. -->>like heap manipulation).
  20. -->
  21. -->In my own work, I've seen many instances where algorithms could be described
  22. -->more succintly with
  23. -->            designator := expr_designator := expression ;
  24. -->to abbreviate
  25. -->            designator := expr_designator ;
  26. -->                  expr_designator := expression ;
  27. -->In this notation, a swap would appear
  28. -->
  29. -->            VAR temp : type_of_designator ;  BEGIN
  30. -->              temp := item1 := item2 := temp ;  END ;
  31. -->--Lee
  32.  
  33. This notation might confuse programmers used to right-associative assigment,
  34. where
  35.     a := b := c
  36. abbreviates
  37.     b := c; a :=b
  38.  
  39. Algol68C had the `displacement operator', :=:= which yield the old value of the
  40. LHS rather than the new value (as yielded by :=).  Thus a swap could be written
  41.     a := b :=:= a
  42.  
  43. This also gave us the equivalent of C's i++:
  44.     i +:=:= 1
  45. and some neat syntax for list operations:
  46.     next OF new item := list head :=:= new item
  47.  
  48. Whether you like such things is a matter of taste.  I did because it meant I could
  49. expression a logically single operation as one statement (or `unit' in A68C-talk).
  50. Likewise, (assuming a C-like stdio library):
  51.     fclose (file :=:= NULL)
  52. meaning "close the file and note that we have no open file" as a single operation.
  53.  
  54. Of course, you can write some pretty bizarre stuff if you want to.  My favourite
  55. was
  56.     ( b | x +:= 1; y | x ) +:= 1
  57.  
  58. -- jP --
  59.  
  60.  
  61.